package logic

import (
	"box-serve/boxserverpc/boxserverpcclient"
	"context"

	"box-serve/api/internal/svc"
	"box-serve/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopAddLogic) ShopAdd(req *types.ShopAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.BoxServeRpc.ShopAdd(l.ctx, &boxserverpcclient.ShopAddRequest{
		Title:      req.Title,
		Price:      float32(req.Price),
		Image:      req.Image,
		Info:       req.Info,
		ClassTitle: req.ClassTitle,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
